const app = getApp()

function getProducts(resolve) {
  app.request({
    url: `${app.globalData.API_URL}/products`,
    success: resolve,
    fail: function () { }
  })
}

function getSlides(resolve) {
  app.request({
    url: `${app.globalData.API_URL}/shop_product_cats`,
    success: resolve,
    fail: function () { }
  })
}

function getdetail(id, resolve) {
  console.log("id", id);
  app.request({
    url: `${app.globalData.API_URL}/shop_product_cats?parent_id=${id}`,
    success: resolve,
    fail: function () { }
  })
}
function getbanner(id, resolve) {
  console.log("id", id);
  app.request({
    url: `${app.globalData.API_URL}/shop_product_cats?id=${id}`,
    success: resolve,
    fail: function () { }
  })
}
function getlist(title, resolve) {
  console.log("title", title);
  app.request({
    url: `${app.globalData.API_URL}/shop_product?cat_title=${title}`,
    success: resolve,
    fail: function () { }
  })
}
function getinfo(id, resolve) {
  console.log("id222", id);
  app.request({
    url: `${app.globalData.API_URL}/shop_product?id=${id}`,
    data: {
      mp_id: getApp().data.mp_id,
    },
    header: {
      "Content-Type": "application/x-www-form-urlencoded"
    },
    success: resolve,
    fail: function () { }
  })
}

function getCategories(data, resolve, reject) {
  app.request({
    url: `${app.globalData.API_URL}/products?type=${data}`,
    success: resolve,
    fail: reject
  })
}

function getOrderinfo(id,resolve) {
  console.log("订单id", id);
  app.request({
    url: `${app.globalData.API_URL}/order?order_id=${id}`,
    success: resolve,
    fail: function () { }
  })
}

function getAbout(resolve) {
  app.request({
    url: `${app.globalData.API_URL}/about`,
    success: resolve,
    fail: function () { }
  })
}


module.exports = {
  getProducts(resolve) {
    return getProducts(resolve)
  },

  getSlides(resolve) {
    return getSlides(resolve)
  },

  getdetail(id, resolve) {
    return getdetail(id, resolve)
  },

  getbanner(id, resolve) {
    return getbanner(id, resolve)
  },
  getlist(title, resolve) {
    return getlist(title, resolve)
  },
  getinfo(id, resolve) {
    return getinfo(id, resolve)
  },
  getOrderinfo(id,resolve) {
    return getOrderinfo(id,resolve)
  },
   getAbout(resolve) {
    return getAbout(resolve)
  },
  getCategories(data, resolve, reject) {
    return getCategories(data, resolve, reject)
  }
}
